using System;
using System.Xml;
using UnityEngine;

namespace AssemblyCSharp
{
	public class SpaceInfoDAO : XmlParserDAO, CommonDAOIF<SpaceDomain>
	{
		private SpaceDomain mSpaceDomain = null;

		public bool readSpaceInfoXml(String fileName)
		{
			return mXmlParser.readXmlFile(fileName);
		}

		public override System.Object parse()
		{
			try
			{
				String returnValue = "";
				mSpaceDomain = new SpaceDomain();

				foreach(XmlNode item in mXmlParser.xmlDoc.ChildNodes)
				{
					GetChildren(item);
				}
				
				return returnValue;
			}
			catch ( Exception e )
			{
				Debug.Log( e.ToString());
				return null;
			}
		}

		private StarDAO mStarDAO = new StarDAO();
		private void GetChildren(XmlNode node)
		{
			if (node.LocalName == Constant.SpaceStar) {
				// Call Star DAO
				mStarDAO.readStarXml(node.OuterXml);
				mStarDAO.parse();
				StarDomain mStarDomain = mStarDAO.getDomain();
				mSpaceDomain.setStar(mStarDomain.Name, mStarDomain);
			} else if (node.LocalName == Constant.SpaceName) {
				mSpaceDomain.Name = node.InnerText;
			} else if (node.LocalName == Constant.SpaceTimeSpeed) {
				mSpaceDomain.TimeSpeed = Convert.ToInt32(node.InnerText);
			}
			else
			{
				foreach (XmlNode item in node.ChildNodes)
				{
					GetChildren(item);
				}
			}
		}
		
		public SpaceDomain getDomain ()
		{
			return mSpaceDomain;
		}
	}
}